
	
	
	
package controller;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import persistency.controller.CourseController;
import persistency.controller.OfferedCourseController;
import persistency.controller.TeacherController;

import model.Course;
import model.OfferedCourse;
import model.Registration;
import model.Student;
import model.Teacher;

public class PlanningController {
	/* Planning controller instance */
	private static PlanningController planningController = new PlanningController();
	
	/* Constructs a new planning controller */
	private PlanningController(){
	}
	/**
	 * singleton
	 * @return
	 */
	/** Returns an instance of the planning controller */
	public static PlanningController getInstance(){
		return planningController;
	}
	

	/** Returns a string representation of offered courses for a given course */
	public String getPlannedCoursesText(Course course) {
		String result = "";
		Collection<OfferedCourse> plannedCourses =OfferedCourseController.instance().getByCourseIDOfferedCourses(course.getCode());
		for (OfferedCourse offeredcourse : plannedCourses) {
			result += offeredcourse.toString() + "\n";
		}
		return result;
	}

	/**
	 * Returns a string representation of the prefered course for a teacher
	 * @param teacher
	 * @return
	 */
	public String getPreferedCoursesText(Teacher teacher) {
		String result = "";
		Collection<Course> preferedCourses = CourseController.instance().getByTeacherIDCoursePreferences(teacher.getTeacherCode()); 
		Iterator<Course> preferedcourseIterator = preferedCourses.iterator();
		while (preferedcourseIterator.hasNext()) {
			result += preferedcourseIterator.next().toString() + "\n";
		}
		return result;
	}


	public void closeOfferedCourseRegistrationByID(Object offeredCourseID) throws Exception {
		OfferedCourse offeredcourse = OfferedCourseController.instance().getOfferedCourse(offeredCourseID);
		offeredcourse.closeRegistration();
		
	}
	
	public void cancelOfferedCourseRegistrationByID(Object offeredCourseID) throws Exception {
		OfferedCourse offeredcourse = OfferedCourseController.instance().getOfferedCourse(offeredCourseID);
		offeredcourse.cancelOfferedCourse();
		
	}
	
	
	
	
}